package com.woniu.finance.service.impl;

import com.woniu.finance.entity.Asset;
import com.woniu.finance.entity.Department;
import com.woniu.finance.mapper.AssetMapper;
import com.woniu.finance.mapper.DepartmentMapper;
import com.woniu.finance.service.IDepartmentService;
import com.woniu.util.utils.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 部门表 服务实现类
 * </p>
 *
 * @author 刘品水
 * @since 2023-04-25
 */
@Service
public class DepartmentServiceImpl  implements IDepartmentService {
    @Autowired(required = false)
    private DepartmentMapper departmentMapper;

    @Override
    public HttpResult<?> findAllDepartment() {
         try {
             List<Department> departments = departmentMapper.selectList(null);
             return new HttpResult<>().ok(departments);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> saveDepartment(Department department) {
        try {
            departmentMapper.insert(department);
            return new HttpResult<>().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> modifyDepartment(Department department) {
        try {
            departmentMapper.updateById(department);
            return new HttpResult<>().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> removeDepartmentById(Integer id) {
        try {
            departmentMapper.deleteById(id);
            return new HttpResult<>().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> findDepartmentById(Integer id) {
        try {
            Department department = departmentMapper.selectById(id);
            return new HttpResult<>().ok(department);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }
}
